<template>
	<view>
		<loading-view v-show="loading"></loading-view>
	</view>
</template>

<script>
	import {
		apiCloudShopCurrentStore,
		apiCloudShopVisit
	} from "@/api/cloudshop"
	import {
		strToParams
	} from "@/utils/tools";
	import Cache from "@/utils/cache";
	export default {
		data() {
			return {
				loading: true,
			};
		},
		onLoad() {
			const options = this.$Route.query
			// console.log('options123', options);
			let clsp_id = options.clspId || strToParams(decodeURIComponent(options.scene)).clspId
			console.log('clsp_id123', clsp_id);

			if (this.$Route.meta.atitle) {
				uni.setNavigationBarTitle({
					title: this.$zhTran(this.$Route.meta.atitle)
				})
			}
			if (parseInt(clsp_id)) {
				Cache.set('clsp_id', clsp_id);
				// 访客记录 
				apiCloudShopVisit({
					clsp_id: clsp_id
				}).finally(() => {
					setTimeout(() => {
						this.$Router.replace({
							path: '/pages/category/category',
						})
					}, 500)
				})
			} else {
				apiCloudShopCurrentStore()
					.then((res) => {
						console.log('res', res)
						if (res.store_list.length > 0) {
							let store_id = res.store_list[0]
							// 访客记录 
							Cache.set('clsp_id', store_id);
							apiCloudShopVisit({
								clsp_id: store_id
							}).finally(() => {
								setTimeout(() => {
									this.$Router.replace({
										path: '/pages/category/category',
									})
								}, 500)
							})
						} else {
							// 访客记录 
							Cache.set('clsp_id', res.store_id);
							apiCloudShopVisit({
								clsp_id: res.store_id
							}).finally(() => {
								setTimeout(() => {
									this.$Router.replace({
										path: '/pages/category/category',
									})
								}, 500)
							})
						}
					}).catch((err) => {
						console.log('err', err)
					})
			}
		}
	};
</script>

<style lang="scss">
</style>